package com.campus.service.impl;

import com.campus.dao.ManagerStudentMapper;
import com.campus.entry.ManagerStudent;
import com.campus.entry.SysUser;
import com.campus.exception.BusinessException;
import com.campus.response.ResultCode;
import com.campus.service.ManagerStudentService;
import com.campus.service.SysUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;

@Service
public class ManagerStudentServiceImpl implements ManagerStudentService {
    @Autowired
    private ManagerStudentMapper managerStudentMapper;
    @Autowired
    private SysUserService sysUserService;

    /**
     * 新增学员
     * @param managerStudent
     */
    @Override
    public void addStudent(ManagerStudent managerStudent) {
        Integer userId=managerStudent.getLoginId();
        SysUser sysUserById = sysUserService.getSysUserById(userId);
        if (Objects.isNull(sysUserById)){
            throw new BusinessException(ResultCode.NO_REGISTER);
        }
        managerStudentMapper.insert(managerStudent);

    }

    /**
     * 批量导入学员
     * @param managerStudentList
     */
    @Override
    public void addStudentList(List<ManagerStudent> managerStudentList) {
        for (ManagerStudent managerStudent : managerStudentList) {
            addStudent(managerStudent);
        }
    }
}
